package org.linuxgears.BouncingBall.model.context;

import java.awt.*;

import org.linuxgears.BouncingBall.model.Ball;
import org.linuxgears.BouncingBall.mover.Mover;
import org.linuxgears.BouncingBall.mover.MovingContext;

/**
 * Created by IntelliJ IDEA.
 * User: khilkeol
 * Date: 31 ���� 2010
 * Time: 11:00:13
 * To change this template use File | Settings | File Templates.
 */
public class BallContext implements MovingContext<Ball> {

    private Mover<Ball> mover;
    private ContextMutator<BallContext> mutator;

    private Ball ball;				// ball, this context is for
    private Rectangle bounds;		// bounds for the ball
    private Point position;			// position within the context

    private BallRunnable ballRunnable;

    public BallContext(Ball ball, Rectangle bounds, Point position, Mover<Ball> mover) {
    	this.ball = ball;
        this.position = position;
        this.bounds = bounds;
        this.mover = mover;
        this.mover.setContext(this);
    }

    public Rectangle getBounds() {
        return bounds;
    }

    public void setBounds(Rectangle bounds) {
        this.bounds = bounds;
    }

    public Point getPosition() {
        return position;
    }

    public void setPosition(Point position) {
        this.position = position;
    }
    
    public Ball getMovable() {
		return ball;
	}

	public Mover<Ball> getMover() {
		return mover;
	}

	public BallRunnable getBallRunnable() {
    	if (ballRunnable == null) {
    		ballRunnable = new BallRunnable(this);
    		(new Thread(ballRunnable)).start();
    	}
    	return ballRunnable;
	}

    
    public ContextMutator<BallContext> getMutator() {
		return mutator;
	}

	public void setMutator(ContextMutator<BallContext> mutator) {
		this.mutator = mutator;
	}
	
	public void mutate() {
		if (mutator != null) {
			mutator.mutate(this);
		};
	}
    
}
